package com.dw.etl.core.service;

import com.dw.etl.common.util.UUIDUtil;
import  com.dw.etl.common.vo.PaginationVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.dw.etl.core.api.EtlLogXxltobatchService;
import com.dw.etl.core.mapper.EtlLogXxltobatchMapper;
import com.dw.etl.core.bean.model.EtlLogXxltobatch;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Map;

/**
 * etlLogXxltobatch服务实现类
 * Created by hozeData on 2021/07/19.
 */
@Service
public class EtlLogXxltobatchServiceImpl implements EtlLogXxltobatchService{

    private static final Logger LOGGER = LoggerFactory.getLogger(EtlLogXxltobatchServiceImpl.class);

    @Autowired
    private EtlLogXxltobatchMapper etlLogXxltobatchMapper;

    @Override
    public int insert(EtlLogXxltobatch etlLogXxltobatch) {
        if(StringUtils.isEmpty(etlLogXxltobatch.getIdXxltobatch())){
            String uuid32 = UUIDUtil.getUUID32();
            etlLogXxltobatch.setIdXxltobatch(uuid32);
        }
        return etlLogXxltobatchMapper.insert(etlLogXxltobatch);
    }

    @Override
    public int insertSelective(EtlLogXxltobatch etlLogXxltobatch)  {
        if(StringUtils.isEmpty(etlLogXxltobatch.getIdXxltobatch())){
            String uuid32 = UUIDUtil.getUUID32();
            etlLogXxltobatch.setIdXxltobatch(uuid32);
        }
        return etlLogXxltobatchMapper.insertSelective(etlLogXxltobatch);
    }

    @Override
    public int deleteById(String id)  {
        return etlLogXxltobatchMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int updateByIdSelective(EtlLogXxltobatch etlLogXxltobatch)  {

        return etlLogXxltobatchMapper.updateByPrimaryKeySelective(etlLogXxltobatch);
    }

    @Override
    public int updateById(EtlLogXxltobatch etlLogXxltobatch)  {
        return etlLogXxltobatchMapper.updateByPrimaryKey(etlLogXxltobatch);
    }

    @Override
    public EtlLogXxltobatch getById(String id)  {
        return etlLogXxltobatchMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<EtlLogXxltobatch> findByModel(EtlLogXxltobatch etlLogXxltobatch)  {
        return etlLogXxltobatchMapper.findByModel(etlLogXxltobatch);
    }

    @Override
    public PaginationVO<EtlLogXxltobatch> findPageByModel(EtlLogXxltobatch etlLogXxltobatch, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum == null? 1 : pageNum, pageSize == null? 10 : pageSize);
        List<EtlLogXxltobatch> quesList = etlLogXxltobatchMapper.findByModel(etlLogXxltobatch);
        PageInfo<EtlLogXxltobatch> pageInfo = new PageInfo<>(quesList);
        PaginationVO<EtlLogXxltobatch> paginationVo = new PaginationVO(pageInfo.getTotal(), pageInfo.getList());
        return paginationVo;
    }

    @Override
    public List<Map<String, Object>> findFaildNum() {
        return etlLogXxltobatchMapper.findFaildNum();
    }
}
